package com.ruoyi.pg.pensionProject.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pg.pensionProject.vo.PgRoleProjectVo;
import com.ruoyi.pg.pensionProject.service.IPgRoleProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 角色项目关联Controller
 *
 * @author Ming
 * @date 2025-09-09
 */
@Api(tags = "角色项目关联Controller")
@RestController
@RequestMapping("/pensionProject/roleProject")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PgRoleProjectController extends BaseController {

    private final IPgRoleProjectService pgRoleProjectService;

    @ApiOperation("查询角色项目关联列表")
    @GetMapping("/list")
    public TableDataInfo<PgRoleProjectVo> list(PgRoleProjectVo entity) {
        return pgRoleProjectService.queryList(entity);
    }

    @ApiOperation("查询角色项目关联所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(PgRoleProjectVo entity) {
        return AjaxResult.success("查询成功", pgRoleProjectService.queryAll(entity));
    }

    @ApiOperation("查询角色项目关联所有列表")
    @GetMapping("/ids")
    public AjaxResult getIds(PgRoleProjectVo entity) {
        return AjaxResult.success("查询成功", pgRoleProjectService.getIds(entity));
    }

    @ApiOperation("导出角色项目关联列表")
    @Log(title = "角色项目关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PgRoleProjectVo entity) {
        List<PgRoleProjectVo> list = pgRoleProjectService.queryAll(entity);
        ExcelUtil<PgRoleProjectVo> util = new ExcelUtil<>(PgRoleProjectVo.class);
        util.exportExcel(response, list, "角色项目关联数据");
    }

    @ApiOperation("获取角色项目关联详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", pgRoleProjectService.queryById(id));
    }

    @ApiOperation("新增角色项目关联")
    @Log(title = "角色项目关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PgRoleProjectVo entity) {
        return toAjax(pgRoleProjectService.save(entity));
    }

    @ApiOperation("新增角色项目关联")
    @Log(title = "角色项目关联", businessType = BusinessType.INSERT)
    @PostMapping("insertBatch")
    public AjaxResult insertBatch(@RequestBody PgRoleProjectVo entity) {
        pgRoleProjectService.insertBatch(entity);
        return AjaxResult.success("设置成功");
    }

    @ApiOperation("修改角色项目关联")
    @Log(title = "角色项目关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PgRoleProjectVo entity) {
        return toAjax(pgRoleProjectService.updateById(entity));
    }

    @ApiOperation("删除角色项目关联")
    @Log(title = "角色项目关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pgRoleProjectService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
